package model
{
	
	import com.sogeti.mentormatch.data.*;
	
	import mx.collections.ArrayCollection;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.remoting.RemoteObject;
	
	
	[Bindable]
	public class MentorMatchModelLocator 
	{
		private static var modelLocator : MentorMatchModelLocator;
		
		public static const MASTER_VIEW_NOT_LOGGED_IN : String = "loginView";
		public static const MASTER_VIEW_LOGGED_IN : String = "allQuestionView";
		
		//testing
		public static var answerService:RemoteObject = new RemoteObject("answerService");
		public static var questionService:RemoteObject = new RemoteObject("questionService");
		public static var assignmentService:RemoteObject = new RemoteObject("assignmentService");
		public static var practiceService:RemoteObject = new RemoteObject("practiceService");
		public static var staticTextService:RemoteObject = new RemoteObject("staticTextService");
		public static var employeeGradeService:RemoteObject = new RemoteObject("employeeGradeService");
		public static var userService:RemoteObject = new RemoteObject("userService");
		public static var authenticationService:RemoteObject = new RemoteObject("authenticationService");
		
		
		public var questionAC:ArrayCollection;
		public var currentQuestion:int;
		public var user:User;
		public var numberOfQuestions:int;
		
		public static function getInstance() : MentorMatchModelLocator
		{
			if (modelLocator == null)
			{
				modelLocator = new MentorMatchModelLocator();
			}
			return modelLocator;
		}
		
		
		public function MentorMatchModelLocator()
		{
			if( modelLocator != null )
			{
				throw new Error("Only one Mentor match model locator instance should be instantiated");
			}
			else{
				init();
			}
			
		}
		
		private function init():void
		{
			masterNavigationStateString = MASTER_VIEW_LOGGED_IN;
			fillQuestionAc();
			currentQuestion=0;
			
		}
		
		public function advanceCurrentQuestion():void
		{
			currentQuestion++;
		}
		
		public function getCurrentQuestion():Question
		{
			return questionAC[currentQuestion];
		}
		
		public function getNumberOfQuestions():int
		{
			return numberOfQuestions;		
		}
		public function getCurrent():int
		{
			return currentQuestion;
		}
		public function addQuestion():void
		{
			/*var question:Question = new Question();
			var answer1:Answers = new Answers(0, "default"); 
			var answer2:Answers = new Answers(1, "default");
			var answer:ArrayCollection = new ArrayCollection();
			answer.addItem(answer1);
			answer.addItem(answer2);
			question.fillQuestion(0,"default", answer);
			
			questionAC.addItem(question);*/
		}
		private function fillQuestionAc():void
		{
			questionService.findAll.addEventListener("result", fillQuestionAcHandler);
			questionService.addEventListener("fault", onFault); 
			questionService.findAll();
		}
		
		private function fillQuestionAcHandler(event:ResultEvent) : void
		{
			questionAC = event.result as ArrayCollection;
		}
		
		public function onFault(fault:String):void {
        	trace('fault' + fault);
    	}
	
	public var masterNavigationStateString:String;
	
	
	public var practices:Array = [{label:"Java Practice -- we rock!", data:1},
			{label:"Microsoft Practice -- like the evil empire!", data:2},
			{label:"BA/PM Practice -- we like to make word docs!", data:3},
			{label:"Database Practice -- we do it on tables!", data:4},
			{label:"PLM Practice -- No one really knows what we do!", data:5},
			{label:"Sales Practice -- Selling stuff we cant explain everyday!", data:6},
			{label:"Management Practice -- we dont do the work, we wanna manage the work!", data:7}];
	
	
	}
}